#include<bits/stdc++.h>
#include<windows.h>
#include "dialogue.h"
#include "chart.h"
using namespace std;
/*
申明：编号0为正常站立
主角默认操控0
*/
namespace character {
	const double RunSpeed = 6.0;
	const double WalkSpeed = 3.0;
	const double eps = 0.00001; //精度误差
	const int frame = 5; //一遍行走动画的帧数
	const int Time = 100; //播放一帧所需要的毫秒数
	const int DefaultFps = 30;
	bool Equal(double X, double Y) {
		return (X - Y >= -eps && X - Y <= eps);
	}
	//默认帧率为30
	double fps=DefaultFps;
	void Update(int Rank, char direction, int numbering) {
		
	}
	class player {
		double x, y; //x和y一定要是整数
	public:
		void SetPos(double X, double Y,char direction,int numbering) {
			x = X, y = Y;
			Update(0,direction,numbering);
			return;
		}
		pair<int, int>GetPos() {
			return {x, y};
		}
		void setFPS(double Fps) {
			fps = Fps;
			return;
		}
		double GetDistance(double X, double Y) {
			return abs(X - x) + abs(Y - y);
		}
		void Move(double ChangeOfx, double ChangeOfy, bool Run, int numbering) {
			double Speed = 0;
			if (Run) { //疾跑状态下
				Speed = RunSpeed;
			} else {//行走状态下
				Speed = WalkSpeed;
			}
			int Cnt = 1;
			if (Equal(ChangeOfx, 0.0)) { //移动y轴
				if (ChangeOfy > 0.0) { //正移动
					while (ChangeOfy > 0.0) {
						Sleep(1000.0 / fps);
						y += Speed / fps;
						ChangeOfy -= Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'U', numbering);
						Cnt++;
					}
				} else {
					while (ChangeOfy < 0.0) {
						Sleep(1000.0 / fps);
						y -= Speed / fps;
						ChangeOfy += Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'D', numbering);
						Cnt++;
					}
				}
			} else {
				if (ChangeOfx > 0.0) {
					while (ChangeOfx > 0.0) {
						Sleep(1000.0 / fps);
						x += Speed / fps;
						ChangeOfx -= Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'R', numbering);
						Cnt++;
					}
				} else {
					while (ChangeOfx < 0.0) {
						Sleep(1000.0 / fps);
						x -= Speed / fps;
						ChangeOfx += Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'L', numbering);
						Cnt++;
					}
				}
			}
		}
	};
	class NPC {
		double x, y; //x和y一定要是整数
	public:
		void SetPos(double X, double Y) {
			x = X, y = Y;
			return;
		}
		void setFPS(double Fps) {
			fps = Fps;
			return;
		}
		pair<int, int>GetPos() {
			return {x, y};
		}
		double GetDistance(double X, double Y) {
			return abs(X - x) + abs(Y - y);
		}
		void Move(double ChangeOfx, double ChangeOfy, bool Run, int numbering) {
			double Speed = 0;
			if (Run) { //疾跑状态下
				Speed = RunSpeed;
			} else {//行走状态下
				Speed = WalkSpeed;
			}
			int Cnt = 1;
			if (Equal(ChangeOfx, 0.0)) { //移动y轴
				if (ChangeOfy > 0.0) { //正移动
					while (ChangeOfy > 0.0) {
						Sleep(1000.0 / fps);
						y += Speed / fps;
						ChangeOfy -= Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'U', numbering);
						Cnt++;
					}
				} else {
					while (ChangeOfy < 0.0) {
						Sleep(1000.0 / fps);
						y -= Speed / fps;
						ChangeOfy += Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'D', numbering);
						Cnt++;
					}
				}
			} else {
				if (ChangeOfx > 0.0) {
					while (ChangeOfx > 0.0) {
						Sleep(1000.0 / fps);
						x += Speed / fps;
						ChangeOfx -= Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'R', numbering);
						Cnt++;
					}
				} else {
					while (ChangeOfx < 0.0) {
						Sleep(1000.0 / fps);
						x -= Speed / fps;
						ChangeOfx += Speed / fps;
						Update(((int)(Cnt * 1000.0 / fps / Time)) % frame + 1, 'L', numbering);
						Cnt++;
					}
				}
			}
		}
		void OutPut(char s){
			
		}
		
	};
}
